<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/24
 * Time: 上午12:01
 */

namespace App\Http\Service;


use App\Http\Repository\OrderRepository;

class OrderService extends Service
{

    /**
     * @param OrderRepository $repository
     */
    public function __construct(OrderRepository $repository)
    {

        parent::__construct($repository);
    }

    /**
     * @param array $params
     * @param int $offset
     * @param int $limit
     * @param array $columns
     */
    public function searchByParams(array $params, $offset, $limit, array $columns = ['*'])
    {

        $where = [];

        foreach ($params as $key => $param) {

            $operator = '=';

            if (in_array($key, ['order_sn', 'store_name', 'buyer_name'])) $operator = 'LIKE';

            if (in_array($key, ['store_id', 'status'])) $operator = '=';

            $where[] = $this->getWhereClause($key, $param, $operator);

        }

        $this->repository->getOrderList($where, $offset, $limit, $columns);

    }

    public function getDiscount()
    {
        
    }

    /**
     * @param int $price
     * @param float $discount
     */
    public function getTotal($price, $discount)
    {
        
    }

    public function store()
    {

    }

}